package edu.pitt.myptm.scheduler;

import java.util.Set;

import org.jgrapht.alg.CycleDetector;
import org.jgrapht.graph.DefaultDirectedGraph;
import org.jgrapht.graph.DefaultEdge;

import edu.pitt.myptm.MyCommand;

public class DeadLockManager {

	public Integer SelectVictim(DefaultDirectedGraph<Integer, DefaultEdge> WFG){
		CycleDetector detector= new CycleDetector<Integer, DefaultEdge>(WFG);
		Set<Integer> cycleVertices = detector.findCycles();
		
		for(int i=0;i<cycleVertices.size();i++){
			
		}
		return cycleVertices.iterator().next();
//		return false;
	}
	
//	public void updateWFG(Graph WFG){
		
//	}
	
	public boolean DetectDeadlock(DefaultDirectedGraph<Integer, DefaultEdge> WFG){
		CycleDetector detector= new CycleDetector<Integer, DefaultEdge>(WFG);
		return detector.detectCycles();
		//return false;
	}
}
